@echo off
chcp 65001
title 下载NSSM工具

echo === 正在下载NSSM工具 ===
echo NSSM是一个将普通应用程序安装为Windows服务的工具

:: 创建tools目录
set "NSSM_DIR=%~dp0tools\nssm"
if not exist "%NSSM_DIR%" (
    mkdir "%NSSM_DIR%" 2>nul
)

:: 下载NSSM
echo 正在下载NSSM...
powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri 'https://nssm.cc/release/nssm-2.24.zip' -OutFile '%NSSM_DIR%\nssm.zip'}"
if errorlevel 1 (
    echo 下载失败，请手动下载NSSM并解压
    echo 下载地址: https://nssm.cc/release/nssm-2.24.zip
    pause
    exit /b 1
)

:: 解压NSSM
echo 正在解压NSSM...
powershell -Command "& {Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('%NSSM_DIR%\nssm.zip', '%NSSM_DIR%')}"
if errorlevel 1 (
    echo 解压失败，请手动解压下载的nssm.zip文件
    pause
    exit /b 1
)

echo.
echo NSSM工具已成功下载并解压到: %NSSM_DIR%
echo 现在您可以运行install_app_with_nssm.bat安装云打印应用程序服务
echo.
pause 